package com.cwnu.onlinemall.service;

import com.cwnu.onlinemall.mapper.MallOrderlistMapper;
import com.cwnu.onlinemall.pojo.MallCommodity;
import com.cwnu.onlinemall.pojo.MallCommodityExample;
import com.cwnu.onlinemall.pojo.MallOrderlist;
import com.cwnu.onlinemall.pojo.MallOrderlistExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderListServiceImpl implements OrderListService {
    @Autowired
    MallOrderlistMapper mallOrderlistMapper;
    @Override
    public List<MallOrderlist> SelectAll() {
        return mallOrderlistMapper.selectByExample(null);
    }

    @Override
    public Integer insert(MallOrderlist mallOrderlist) {
        return mallOrderlistMapper.insertSelective(mallOrderlist);
    }

    @Override
    public MallOrderlist selectById(Integer id) {
        return mallOrderlistMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MallOrderlist> selectByCommodityName(String name) {
        MallOrderlistExample mallOrderlistExample=new MallOrderlistExample();
        MallOrderlistExample.Criteria criteria=mallOrderlistExample.or();
        criteria.andCommodityNameEqualTo(name);
        return mallOrderlistMapper.selectByExample(mallOrderlistExample);
    }

    @Override
    public Integer updateById(MallOrderlist mallOrderlist) {
        return mallOrderlistMapper.updateByPrimaryKeySelective(mallOrderlist);
    }

    @Override
    public Integer deleteById(Integer id) {
        return mallOrderlistMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<MallOrderlist> selectByCustomerId(Integer id) {
        MallOrderlistExample mallOrderlistExample=new MallOrderlistExample();
        MallOrderlistExample.Criteria criteria=mallOrderlistExample.or();
        criteria.andCustomerIdEqualTo(id);
        return mallOrderlistMapper.selectByExample(mallOrderlistExample);
    }

    @Override
    public List<MallOrderlist> selectByCategoryName(String category) {
        MallOrderlistExample mallOrderlistExample=new MallOrderlistExample();
        MallOrderlistExample.Criteria criteria=mallOrderlistExample.or();
        criteria.andCommodityCategoryEqualTo(category);
        return mallOrderlistMapper.selectByExample(mallOrderlistExample);

    }
}
